package com.vietnam.power.persitence;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.vietnam.power.domain.Root;

/**
 * The persistent class for the product_group database table.
 * 
 */
@Entity
@Table(name = "product_group")
public class ProductGroup implements Serializable, Root {
	private static final long serialVersionUID = 1L;
	private int id;
	private Date createdDate;
	private String description;
	private String keyword;
	private String name;
	private boolean status;
	private List<Product> products;
	private UserInfo userInfo;
	private List<SubProductGroup> subProductGroups1;
	private List<SubProductGroup> subProductGroups2;

	public ProductGroup() {
	}

	public ProductGroup(int id) {
		this.id = id;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "created_date")
	public Date getCreatedDate() {
		return this.createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getKeyword() {
		return this.keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean getStatus() {
		return this.status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	// bi-directional many-to-one association to Product
	@OneToMany(mappedBy = "productGroup")
	public List<Product> getProducts() {
		return this.products;
	}

	public void setProducts(List<Product> products) {
		this.products = products;
	}

	public Product addProduct(Product product) {
		getProducts().add(product);
		product.setProductGroup(this);

		return product;
	}

	public Product removeProduct(Product product) {
		getProducts().remove(product);
		product.setProductGroup(null);

		return product;
	}

	// bi-directional many-to-one association to UserInfo
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "created_by")
	public UserInfo getUserInfo() {
		return this.userInfo;
	}

	public void setUserInfo(UserInfo userInfo) {
		this.userInfo = userInfo;
	}

	// bi-directional many-to-one association to SubProductGroup
	@OneToMany(mappedBy = "productGroup1", cascade = CascadeType.ALL, orphanRemoval=true)
	public List<SubProductGroup> getSubProductGroups1() {
		if (this.subProductGroups1 == null) {
			this.subProductGroups1 = new ArrayList<SubProductGroup>();
		}
		return this.subProductGroups1;
	}

	public void setSubProductGroups1(List<SubProductGroup> subProductGroups1) {
		this.subProductGroups1 = subProductGroups1;
	}

	public SubProductGroup addSubProductGroups1(SubProductGroup subProductGroups1) {
		getSubProductGroups1().add(subProductGroups1);
		subProductGroups1.setProductGroup1(this);

		return subProductGroups1;
	}

	public SubProductGroup removeSubProductGroups1(SubProductGroup subProductGroups1) {
		getSubProductGroups1().remove(subProductGroups1);
		subProductGroups1.setProductGroup1(null);

		return subProductGroups1;
	}

	// bi-directional many-to-one association to SubProductGroup
	@OneToMany(mappedBy = "productGroup2", cascade = CascadeType.ALL, orphanRemoval=true)
	public List<SubProductGroup> getSubProductGroups2() {
		return this.subProductGroups2;
	}

	public void setSubProductGroups2(List<SubProductGroup> subProductGroups2) {
		this.subProductGroups2 = subProductGroups2;
	}

	public SubProductGroup addSubProductGroups2(SubProductGroup subProductGroups2) {
		getSubProductGroups2().add(subProductGroups2);
		subProductGroups2.setProductGroup2(this);

		return subProductGroups2;
	}

	public SubProductGroup removeSubProductGroups2(SubProductGroup subProductGroups2) {
		getSubProductGroups2().remove(subProductGroups2);
		subProductGroups2.setProductGroup2(null);

		return subProductGroups2;
	}

}